<?php
namespace app\model\frontend;
use think\Model;
use think\facade\Log;
class PaylogModel extends Model{

    protected $table = 'sh_core_paylog'; 
    public static function insert2( $data ){

        $date = date('Y-m-d H:i:s');
        $dataStr = json_encode( $data );
        $sql = "insert into sh_core_paylog set "
                // . " notify_id='" .  $data['id'] . "'"
                . "transaction_id='" . $data['transaction_id'] . "'"  
                . ",mchid='" . $data['mchid'] . "'"  
                . ",success_time='" . $data['success_time'] . "'"  
                . ",openid='" . $data['payer']['openid'] . "'"  
                . ",out_trade_no='" . $data['out_trade_no'] . "'"  
                . ",appid='" . $data['appid'] . "'"  
                . ",trade_state='" . $data['trade_state'] . "'"  
                . ",trade_type='" . $data['trade_type'] . "'"  
                . ",payer_total='" . $data['amount']['payer_total'] . "'"  
                . ",total='" . $data['amount']['total'] . "'"  
                . ",currency='" . $data['amount']['currency'] . "'"  
                . ",payer_currency='" . $data['amount']['payer_currency'] . "'"  
                . ",content='" . $dataStr . "'"  
                . ",created_at='" . $date . "'"  
                . ",updated_at='" . $date . "'"  
                .";"
        ;
        
        Log::write( $sql );
        return pdo_query( $sql );

    }

    public static function update2( $data ){

        $date = date('Y-m-d H:i:s');
        $dataStr = json_encode( $data );
        $sql = "update sh_core_paylog set "
                // . " notify_id='" .  $data['id'] . "'"
                // . ",transaction_id='" . $data['transaction_id'] . "'"  
                . "mchid='" . $data['mchid'] . "'"  
                . ",success_time='" . $data['success_time'] . "'"  
                . ",openid='" . $data['payer']['openid'] . "'"  
                . ",out_trade_no='" . $data['out_trade_no'] . "'"  
                . ",appid='" . $data['appid'] . "'"  
                . ",trade_state='" . $data['trade_state'] . "'"  
                . ",trade_type='" . $data['trade_type'] . "'"  
                . ",payer_total='" . $data['amount']['payer_total'] . "'"  
                . ",total='" . $data['amount']['total'] . "'"  
                . ",currency='" . $data['amount']['currency'] . "'"  
                . ",payer_currency='" . $data['amount']['payer_currency'] . "'"  
                . ",content='" . $dataStr . "'"
                . ",updated_at='" . $date . "'"
                . " where transaction_id = '" . $data['transaction_id'] . "'"  
                .";"
        ;
        Log::write( $sql );
        return pdo_query( $sql );

    }



}